"""
建立多索引
"""
import pandas as pd

def mutilindex_gen_test():
    df = pd.DataFrame({'row': [0, 1, 2],
                       'One_X': [1.1, 1.1, 1.1],
                       'One_Y': [1.2, 1.2, 1.2],
                       'Two_X': [1.11, 1.11, 1.11],
                       'Two_Y': [1.22, 1.22, 1.22]})
    df = df.set_index("row")
    print("df:\n", df)
    df.columns = pd.MultiIndex.from_tuples([tuple(c.split('_')) for c in df.columns])
    print("df.columns:\n", df.columns)
    print("df:\n", df)
    print("df:\n", df.stack(0).reset_index(1))
    print("df:\n", df.stack(0).reset_index(0))


if __name__ == '__main__':
    mutilindex_gen_test()